home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Fudd source Folder / Prepare ƒ / MSG Shell ƒ / msg shell main.c < prev    next >
C/C++ Source or Header  |  1993-11-07  |  3KB  |  122 lines

  1. /**********************************************************************\
  2.  
  3. File:        msg shell main.c
  4.  
  5. Purpose:    This module handles the event loop and event dispatching.
  6.  
  7.  
  8. MSG Prepare 1.0 -- minimal integrity check preparation program
  9. Copyright (C) 1993 Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "msg main.h"
  29. #include "msg menus.h"
  30. #include "MSG Prepare.h"
  31.  
  32. EventRecord        gTheEvent;
  33.  
  34. void main(void)
  35. {    
  36.     gDone = FALSE;    
  37.     MaxApplZone();
  38.     InitGraf(&thePort);
  39.     InitFonts();
  40.     FlushEvents(everyEvent, 0);
  41.     InitWindows();
  42.     InitMenus();
  43.     TEInit();
  44.     InitDialogs(0L);
  45.     InitCursor();
  46.     GetDateTime(&randSeed);
  47.     CheckDropKick();
  48.     if (gDone)
  49.         ExitToShell();
  50.     InitEnvironment();    
  51.     EventLoop();    
  52.     ExitToShell();
  53. }
  54.  
  55. void InitEnvironment(void)
  56. {
  57.     Handle        MBARHandle;
  58.  
  59.     MBARHandle = GetNewMBar(400);
  60.     SetMenuBar(MBARHandle);
  61.     gAppleMenu = GetMHandle(appleMenu);
  62.     gFileMenu = GetMHandle(fileMenu);
  63.     gEditMenu = GetMHandle(editMenu);
  64.  
  65.     AddResMenu(gAppleMenu, 'DRVR');
  66.     AdjustMenus();
  67. }
  68.  
  69. void EventLoop(void)
  70. {
  71.     while(!gDone)
  72.     {
  73.         SetCursor(&arrow);
  74.         HiliteMenu(0);
  75.         if (WaitNextEvent(everyEvent, &gTheEvent, 30, 0L))
  76.             DispatchEvents();
  77.     }
  78. }
  79.  
  80. void DispatchEvents(void)
  81. {
  82.     int            i;
  83.     
  84.     switch (gTheEvent.what)
  85.     {
  86.         case nullEvent:
  87.             break;
  88.         case mouseDown:
  89.             HandleMouseDown();
  90.             break;
  91.         case keyDown:
  92.         case autoKey:
  93.             if(gTheEvent.modifiers & cmdKey)
  94.             {
  95.                 AdjustMenus();
  96.                 HandleMenu(MenuKey((char)(gTheEvent.message & charCodeMask)));
  97.             }
  98.             break;
  99.     }
  100. }
  101.  
  102. void HandleMouseDown(void)
  103. {
  104.     WindowPtr    theWindow;
  105.     int            windowCode = FindWindow(gTheEvent.where, &theWindow);
  106.     
  107.     switch (windowCode)
  108.     {
  109.         case inMenuBar:
  110.             AdjustMenus();
  111.             HandleMenu(MenuSelect(gTheEvent.where));
  112.             break;
  113.         case inContent:
  114.             if(FrontWindow() != theWindow)
  115.                 SelectWindow(theWindow);
  116.             break;
  117.         case inSysWindow:
  118.             SystemClick(&gTheEvent, theWindow);
  119.             break;
  120.     }
  121. }
  122.